home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c1.zip / IOS1_20.ASM < prev    next >
Assembly Source File  |  1987-06-18  |  9KB  |  311 lines

  1.  
  2. title   Level 1 I/O Functions for Lattice 'c' Version 1.04
  3. page    64,132
  4. name    IOS1_20 ;DOS function calls 3DH, 3EH, 3FH, 40H, AND 42H.
  5. comment |
  6.    These functions take advantage of DOS 2.0 and will directly
  7. replace the original level 1 I/O except that 'text mode' is
  8. not supported.  DOS error numbers are saved at ERRNO and may be
  9. checked by including: "extern short errno;" in your source files.
  10. Note that the pmode parameter in creat is forced to zero, due to
  11. a problem with Lattice's freopen which passes a 1A4H to creat.
  12.  
  13.                         Ted Reuss     c/o South Texas Software, Inc.
  14.                   Home: 713/961-3926      4544 Post Oak Place, Suite 176
  15.                   Offi: 713/877-8205      Houston, Tx 77027
  16.         |
  17.         public  CREAT, OPEN, CLOSE, READ, WRITE, LSEEK
  18. dgroup  group   data
  19. data    segment word public 'data'
  20.         assume  ds:dgroup
  21.  
  22.         public  ERRNO
  23. ERRNO   dw      0       ; DOS error number (DOS Manual page D-14)
  24. data    ends
  25.  
  26. pgroup  group   prog
  27. prog    segment byte public 'prog'
  28.         assume  cs:pgroup
  29.  
  30.         subttl  CREAT -- create a new file
  31.         page
  32. ;
  33. ; NAME
  34. ;       creat -- create a new file
  35. ;
  36. ; SYNOPSIS
  37. ;
  38. ;       file = creat(name, pmode);
  39. ;       int file;       file number or error code
  40. ;       char *name;     file name (valid drive\path\filespec)
  41. ;       int pmode;      access privilege mode bits, DOS attribute
  42. ;                       NOTE: forced to zero in current version.
  43. ;
  44. ; DESCRIPTION
  45. ;
  46. ;       Creates a new file with the specified name and prepares is
  47. ;       for access via the level 1 I/O functions.  The file name
  48. ;       may consist of a valid drive and path name.  All I/O is
  49. ;       done via DOS calls 3fh (READ) and 40h (WRITE).  If the file
  50. ;       already exists, it's contents are discarded.  The current file
  51. ;       position and the end of file are both zero. (indicating an
  52. ;       empty file) if the function is successful. ERRNO is set to
  53. ;       the error number returned by DOS in the event of an error.
  54. ;
  55. ; RETURNS
  56. ;       file = file number to access file, if successful
  57. ;            = -1 if error  (ERRNO get DOS error number)
  58. ;
  59.  
  60.         public  CREAT
  61. CREAT   proc    near
  62.         push    bp
  63.         mov     bp,sp
  64.         mov     dx,[bp+4]       ;get ptr to drive\path\filespec
  65.         xor     cx,cx
  66.         mov     ah,3CH          ;DOS create function
  67.         int     21H
  68.         jnc     cre10
  69.         mov     dgroup:errno,ax
  70.         mov     ax,-1
  71. cre10:  mov     sp,bp
  72.         pop     bp
  73.         ret
  74. CREAT   endp
  75.  
  76.         subttl  OPEN -- open a file
  77.         page
  78. ;
  79. ; NAME
  80. ;       open -- open a file
  81. ;
  82. ; SYNOPSIS
  83. ;
  84. ;       file = open(name, rwmode);
  85. ;       int file;       file number or error code
  86. ;       char *name;     file name (valid drive\path\filespec)
  87. ;       int rwmode;     read/write mode, where 0=read, 1=write,
  88. ;                       2=read/write
  89. ;
  90. ; DESCRIPTION
  91. ;
  92. ;       Opens a file for access using the level 1 I/O functions.
  93. ;       The file name may contain a valid drive and path name.  All
  94. ;       I/O is done via DOS functions 3fh (READ) and 40h (WRITE).
  95. ;       The mode word determines the type of I/O which will be
  96. ;       performed on the file.  The low order bits specify whether
  97. ;       read or write operations (or both) are to be allowed.
  98. ;       In the event of an error the error code passed by DOS is
  99. ;       saved at ERRNO.
  100. ;
  101. ; RETURNS
  102. ;
  103. ;       file = file number to access file, if successful
  104. ;            = -1 if error  (ERRNO get DOS error number)
  105. ;
  106.  
  107.         public  OPEN
  108. OPEN    proc    near
  109.         push    bp
  110.         mov     bp,sp
  111.         mov     dx,[bp+4]       ;get ptr to drive\path\filespec
  112.         mov     ax,[bp+6]       ;get mode
  113.         mov     ah,3DH          ;DOS open function
  114.         int     21H
  115.         jnc     opn10
  116.         mov     dgroup:errno,ax
  117.         mov     ax,-1
  118. opn10:  mov     sp,bp
  119.         pop     bp
  120.         ret
  121. OPEN    endp
  122.  
  123.         subttl  CLOSE -- close a file
  124.         page
  125. ;
  126. ; NAME
  127. ;
  128. ;       close -- close a file
  129. ;
  130. ; SYNOPSIS
  131. ;
  132. ;       status = close(file);
  133. ;       int status;     status code: 0 if successful
  134. ;       int file;       file number for file
  135. ;
  136. ; DESCRIPTION
  137. ;
  138. ;       Close a file and frees the file number for use in accessing
  139. ;       another file.  Any buffers allocated when the file was
  140. ;       opened are released.
  141. ;
  142. ; RETURNS
  143. ;
  144. ;       status = 0 if successful
  145. ;              = -1 if error  (ERRNO get DOS error number)
  146. ;
  147.  
  148.         public  CLOSE
  149. CLOSE   proc    near
  150.         push    bp
  151.         mov     bp,sp
  152.         mov     bx,[bp+4]       ;get file handle
  153.         mov     ah,3EH          ;DOS close function
  154.         int     21H
  155.         jc     clo10
  156.         xor     ax,ax
  157.         jmp     short clo20
  158. clo10:  mov     dgroup:errno,ax
  159.         mov     ax,-1
  160. clo20:  mov     sp,bp
  161.         pop     bp
  162.         ret
  163. CLOSE   endp
  164.  
  165.         subttl  READ -- read data from file
  166.         page
  167. ;
  168. ; NAME
  169. ;
  170. ;       read -- read data from file
  171. ;
  172. ; SYNOPSIS
  173. ;
  174. ;       status = read(file, buffer, length);
  175. ;       int status;     status code or actual length
  176. ;       int file;       file number for file
  177. ;       char *buffer;   input buffer
  178. ;       int length;     number of bytes requested
  179. ;
  180. ; DESCRIPTION
  181. ;
  182. ;       Reads the next set of bytes from a file.  The return count
  183. ;       is always equal to the number of bytes placed in the buffer
  184. ;       and will never exceed the "length" parameter, except in the
  185. ;       case of an error, where -1 is returned.  The file position
  186. ;       is advanced accordingly.
  187. ;
  188. ; RETURNS
  189. ;
  190. ;       status = 0 if end of file
  191. ;              = -1 if error  (ERRNO get DOS error number)
  192. ;              = number of bytes actually read, otherwise
  193. ;
  194.  
  195.         public  READ
  196. READ    proc    near
  197.         push    bp
  198.         mov     bp,sp
  199.         mov     bx,[bp+4]       ;get file handle
  200.         mov     dx,[bp+6]       ;get buffer address
  201.         mov     cx,[bp+8]       ;get byte count
  202.         mov     ah,3FH          ;DOS read function
  203.         int     21H
  204.         jnc     red10
  205.         mov     dgroup:errno,ax
  206.         mov     ax,-1
  207. red10:  mov     sp,bp
  208.         pop     bp
  209.         ret
  210. READ    endp
  211.  
  212.         subttl  WRITE -- write data to file
  213.         page
  214. ;
  215. ; NAME
  216. ;
  217. ;       write -- write data to file
  218. ;
  219. ; SYNOPSIS
  220. ;
  221. ;       status = write(file, buffer, length);
  222. ;       int status;     status code or actual length
  223. ;       int file;       file number for file
  224. ;       char *buffer;   output buffer
  225. ;       int length;     number of bytes in buffer
  226. ;
  227. ; DESCRIPTION
  228. ;
  229. ;       Writes the next set of bytes to a file.  The return count is
  230. ;       equal to the number of bytes written, unless an error
  231. ;       occurred.  The file position is advanced accordingly.
  232. ;
  233. ; RETURNS
  234. ;
  235. ;       status = -1 if error  (ERRNO get DOS error number)
  236. ;              = number of bytes actually written otherwise
  237. ;
  238.  
  239.         public  WRITE
  240. WRITE   proc    near
  241.         push    bp
  242.         mov     bp,sp
  243.         mov     bx,[bp+4]       ;get file handle
  244.         mov     dx,[bp+6]       ;get buffer address
  245.         mov     cx,[bp+8]       ;get byte count
  246.         mov     ah,40H          ;DOS write function
  247.         int     21H
  248.         jnc     wrt10
  249.         mov     dgroup:errno,ax
  250.         mov     ax,-1
  251. wrt10:  mov     sp,bp
  252.         pop     bp
  253.         ret
  254. WRITE   endp
  255.  
  256.         subttl  LSEEK -- seek to specified file position
  257.         page
  258. ;
  259. ; NAME
  260. ;
  261. ;       lseek -- seek to specified file position
  262. ;
  263. ; SYNOPSIS
  264. ;
  265. ;       pos = lseek(file, offset, mode);
  266. ;       long pos;       returned file position or error code
  267. ;       int file;       file number for file
  268. ;       long offset;    desired position
  269. ;       int mode;       offset mode relative to:
  270. ;                       0 = beginning of file       BOFM
  271. ;                       1 = current file position   CURM
  272. ;                       2 = end of file             EOFM
  273. ;
  274. ; DESCRIPTION
  275. ;
  276. ;       Changes the current file position to a new position in the
  277. ;       file.  The offset is specified as a long int and is added to
  278. ;       the current position (mode 1) or to the logical end of file
  279. ;       (mode 2).  Use DOS function 42h (LSEEK).
  280. ;
  281. ; RETURNS
  282. ;
  283. ;       pos = -1L if error occurred (ERRNO get DOS error number)
  284. ;       = new file position if successful
  285. ;
  286.  
  287.         public  LSEEK
  288. LSEEK   proc    near
  289.         push    bp
  290.         mov     bp,sp
  291.         mov     bx,[bp+4]       ;get file handle
  292.         mov     dx,[bp+6]       ;get low word of pos
  293.         mov     cx,[bp+8]       ;get high word of pos
  294.         mov     ax,[bp+10]      ;get seek mode
  295.         mov     ah,42H          ;DOS lseek function
  296.         int     21H
  297.         jnc     lsk10
  298.         mov     dgroup:errno,ax
  299.         mov     ax,-1
  300.         mov     dx,ax
  301. lsk10:  mov     bx,ax
  302.         mov     ax,dx
  303.         mov     sp,bp
  304.         pop     bp
  305.         ret
  306. LSEEK   endp
  307.  
  308. prog    ends
  309.         end
  310.  
  311.